package com.tang.utils;

import org.springframework.util.SerializationUtils;

import java.util.Base64;

/**
 * @author liqilin
 * @since 2021/3/26 13:37
 */
public class Base64SerializationUtils {

    public static <T> String serialize(T data) {
        return Base64.getEncoder().encodeToString(SerializationUtils.serialize(data));
    }

    @SuppressWarnings("unchecked")
    public static <T> T deserialize(String str, Class<T> clazz) {
        return (T) SerializationUtils.deserialize(Base64.getDecoder().decode(str));
    }

}
